package io.adrainty.algorithm.leetcode.lcr;

/**
 * <p>LCR019. 验证回文串 II</p>
 * <a href="https://leetcode.cn/problems/RQku0D/">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @description LCR019
 * @since 2025/7/28 14:31:57
 */
public class LCR019 {

    public boolean validPalindrome(String s) {
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                boolean deleteLeft = validPalindrome(s, l + 1, r);
                boolean deleteRight = validPalindrome(s, l, r - 1);
                return deleteLeft || deleteRight;
            }
            l++; r--;
        }
        return true;
    }

    public boolean validPalindrome(String s, int l, int r) {
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) return false;
            l++; r--;
        }
        return true;
    }

    public static void main(String[] args) {
        LCR019 lcr019 = new LCR019();
        System.out.println(lcr019.validPalindrome("eedede"));
    }

}
